Repository navigation
Keep every annotation field in Annotation.apply_range - #661
Conversation
apply_range filtered sample, label_store, subtype, chan, num and aux_note, but not symbol or description, which then no longer matched sample. It also failed with a TypeError on an annotation read by rdann with the default return_label_elements, where label_store is None. Filter every per-annotation field that is set, keeping arrays as arrays and lists as lists, and leave fields that are not set as None. Calling apply_range on an rdann result now gives the same fields as reading only that range. rdann's own results are unchanged for every annotation file in sample-data, with and without sampfrom, sampto and shift_samps.
tompollard
left a comment
There was a problem hiding this comment.
One issue to address before merging: apply_range() now slices the per-annotation fields, but it leaves contained_labels unchanged if the annotation was previously summarized. That makes the summary disagree with the filtered annotations.
For example, starting with wfdb.rdann("sample-data/100", "atr", summarize_labels=True) and then calling apply_range(sampfrom=600000, sampto=620000) leaves 71 annotations, while contained_labels still counts all 2,274 original annotations. Reading that range directly with rdann(..., sampfrom=600000, sampto=620000, summarize_labels=True) gives a summary count of 71.
Could apply_range() refresh or clear contained_labels when it is present, and add a test for this sequence? The new per-annotation field handling otherwise looks good; the focused offline annotation tests passed.
apply_range kept contained_labels as it was, so after summarize_labels=True the summary still counted every annotation, not only those kept. It now summarizes the labels again when there is a summary, giving the same contained_labels as reading only that range.
|
Thanks, fixed in the latest commit, after merging When the annotation has a label summary, New |
|
Re-reviewed |
## Summary Bump the version from 5.0.0 to 5.1.0, and collect the changelog entries in `changelog.d/` into `docs/changes.rst` with `towncrier build --date "Nov 2026"`, with a short summary at the top of the new section. This is a minor release: it adds `physionet://` URIs and reads `pn_dir` records and downloads databases through the `physionet` package, which becomes a dependency (#657, #658, #659), speeds up `xqrs_detect` and `gqrs_detect` (#655, #656), and fixes `rdann` and `Annotation.apply_range` (#654, #660, #661). The one change existing code may notice is that `rdann` now raises a `ValueError` when `sampto` is not greater than `sampfrom`, including `sampto=0`, which used to return every annotation. The summary calls it out. It also raises the `physionet` requirement from 0.7.1 to 0.7.2, which retries transient server errors when looking up a database's latest version, as `pn_dir` without a version does, and updates that changelog entry to match. ## Checks - `uv run pytest -m "not network"`: 511 passed, also with `--python 3.11 --resolution lowest-direct` (physionet 0.7.2). `uv run pytest -m network`: 18 passed. - `ruff format --check`, `ruff check` and the Sphinx HTML build with warnings as errors pass. - The wheel and source distribution build, pass `twine check`, and have `Version: 5.1.0` and `Requires-Dist: physionet>=0.7.2`. - PyPI has no 5.1.0 release yet. <sub>@tompollard 🟥 red 🦥 sloth</sub>
Follow-up to #654, from the review there.
Annotation.apply_rangefilteredsample,label_store,subtype,chan,numandaux_note, but notsymbolordescription. It also indexedlabel_storeunconditionally, so on record100:apply_rangenow filters every per-annotation field that is set (sample,label_store,symbol,description,subtype,chan,numandaux_note), keeping arrays as arrays and lists as lists, and leaves fields that areNoneas they are. So callingapply_rangeon anrdannresult gives the same fields as reading only that range withrdann.rdanncallsapply_rangeitself whensampfromis given, so I compared every field ofrdannresults before and after this change: for every annotation file insample-data, with no range,sampfrom,sampto, both,shift_samps, and all three label elements (66 reads), the results are identical.Testing:
test_apply_range_keeps_every_field_consistent, for the defaultrdannresult and with all three label elements, checks thatapply_rangegives the same fields asrdann(..., sampfrom=600000, sampto=620000), and that unset fields stayNone. Both cases fail onmain.uv run pytest -m "not network": 493 passed.uv run pytest -m network: 18 passed.ruff format --check,ruff check, the docs build andtowncrier build --draftpass. Changelog entry added inchangelog.d/.@tompollard 🟥 red 🦥 sloth